package Apaper;
import java.io.FileOutputStream;

import java.util.Scanner;
import java.io.FileInputStream;
import java.io.ObjectInputStream;
import java.io.IOException;
import java.util.List;

public class UseExpert{
    public void Use() throws IOException {

        PaperReviewSystem system = new PaperReviewSystem();
        Scanner scanner = new Scanner(System.in);
        int contine1 =0;
        int BB = 0;
        while (BB == 0 ) {
            System.out.println("是否确认？0.是  1.否");
            BB=scanner.nextInt();
            if (BB==1){
                break;
            }
            System.out.println("0.查看论文 1.批改论文 2.退出");
            contine1 = scanner.nextInt();
            switch (contine1) {
                case 0:
                    try (FileInputStream fileIn = new FileInputStream("objects.ser");
                         ObjectInputStream objectIn = new ObjectInputStream(fileIn)) {
                        List<Paper> restoredList = (List<Paper>) objectIn.readObject();
                        // 使用恢复的对象列表
                        for (Paper obj : restoredList) {

                            system.addPaper(obj);
                        }
                    } catch (IOException | ClassNotFoundException e) {
                        System.out.println("请设置论文");
                        e.printStackTrace();
                    }
                    system.getPaper();
                    break;
                case 1:
                    for (int j = 0; j < 5;j++) {
                        try (FileInputStream fileIn = new FileInputStream("object" + j + ".ser");
                             ObjectInputStream objectIn = new ObjectInputStream(fileIn)) {
                            Expert expert = (Expert) objectIn.readObject();
                            // 使用反序列化得到的对象
                            system.addExpert(expert);
                        } catch (IOException | ClassNotFoundException e) {
                            e.printStackTrace();
                            System.out.println("请输入专家名称");
                        }
                    }

                    try (FileInputStream fileIn = new FileInputStream("objects.ser");
                         ObjectInputStream objectIn = new ObjectInputStream(fileIn)) {
                        List<Paper> restoredList = (List<Paper>) objectIn.readObject();
                        // 使用恢复的对象列表
                        for (Paper obj : restoredList) {
                            system.addPaper(obj);
                        }
                    } catch (IOException | ClassNotFoundException e) {
                        System.out.println("请设置论文");
                        e.printStackTrace();
                    }
                    system.assignPapersToExperts();
                    System.out.println("一共"+system.size()+"篇论文");
                    System.out.println("存在问题毕业论文: " + system.countUnqualifiedPapers());
                    System.out.println("复评后合格的论文: " + system.countPapersWithSingleUnqualifiedExpert());
                    System.out.println("初评合格的论文: " + system.countFullyQualifiedPapers());
                    break;
                case 2:
                    break;
            }
        }
    }
}

